package org.afs.gescol.core.dao.implementations;

import java.util.List;

import org.afs.gescol.core.dao.interfaces.DayDao;
import org.afs.gescol.core.model.references.Day;
import org.hibernate.Criteria;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.scub.foundation.framework.core.dao.implementations.HibernateDaoBaseImplementation;

/**
 * Implementation of DayDao.
 * @autor Kobla GBENYO (kobla.gbenyo@gmail.com)
 */
public class DayDaoImpl extends HibernateDaoBaseImplementation implements DayDao {

    @Override
    public Day getDayById(Long id) {
        return load(id, Day.class);
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<Day> getDaysByLabel(String label) {
        final Criteria criteria = createCriteria(Day.class);
        if (label != null && !"".equals(label)) {
            criteria.add(Restrictions.ilike("label", label, MatchMode.ANYWHERE));
        }
        criteria.addOrder(Order.asc("label"));
        return criteria.list();
    }

}
